package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class DVD here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVD
{
    // instance variables - replace the example below with your own
   public int id;
   public String title;
   public String artist;
   public String publicationDate;
   public ArrayList<Copy> copies;
   public DVD(int id, String title, String artist, String publicationDate)
   {
       this.id=id;
       this.title=title;
       this.artist=artist;
       this.publicationDate=publicationDate;
       copies = new ArrayList<Copy>();
    }

    public int getID()
    {
        return id;
    }
    public void addCopy (Copy newItem)
    {
        copies.add(newItem);
    }
    public ArrayList<Copy> getCopies()
    {
        return copies;
    }
    public String getTitle()
    {
        return title;
    }
    public Copy findCopy(int search)
    {
        boolean ok=false;
        int x=0;
        int n=copies.size();
        Copy found=null;
        while(x<n && ok==false)
        {
            if(copies.get(x).getSerialNumber()==search)
            {
                found = copies.get(x);
                ok=true;
            }
            else
            {
                x++;
            }
            
        }
        return found;
    }
    public Copy check()
    {
        int x=0;
        int n;
        n=copies.size();
        boolean ok=false;
        while(x<n && ok==false)
        {
            ok=copies.get(x).getAvailable();
        }
        if(ok==true){
            
                return copies.get(x);}
        else{
            return null;
        }
    }
    public void rentCopy(long loanID, String loanDate, String loanPeriod)
    {
        Copy c = check();
        c.lent(loanID, loanDate, loanPeriod);
    }
}
